﻿<div class="modal-header">
    <div class="assistant_header">
        <button type="button" class="close" data-dismiss="modal" close="true">
            <span aria-hidden="true">×</span>
        </button>
        <h4 class="modal-title">
            <span class="fa fa-legal"></span>选择项目
        </h4>
    </div>
</div>
<style>
    .modal-dialog {
        width: 800px !important;
    }
</style>
<div class="modal-body">

    <form class="new_serach" name="searchForm">
        <div style="display:inline-block;width:100%">
            <span> 项目名：</span>
            <div class="layui-inline layui-form">
                <input class="layui-input" name="keyword1" autocomplete="off">
            </div>

            <span> 状态：</span>
            <div class="layui-form layui-inline" style="width:80px!important;">
                <select name="associated" lay-filter="associated">
                    <option value="0">全部</option>
                    <option value="1">未关联</option>
                    <option value="2">已关联</option>
                </select>
            </div>

            <span> 项目类型：</span>
            <div class="layui-form layui-inline" style="width:80px!important;">
                <select name="library" lay-filter="library">
                    <option value="0">全部</option>
                    <option value="1">招商</option>
                    <option value="2">预备</option>
                    <option value="3">开工</option>
                    <option value="4">重点</option>
                    <option value="5">入统</option>
                    <option value="6">双千</option>
                </select>
            </div>

            <span> 签约状态：</span>
            <div class="layui-form layui-inline" style="width:80px!important;">
                <select name="sign" lay-filter="sign">
                    <option value="0">全部</option>
                    <option value="5">在谈</option>
                    <option value="1">待签约</option>
                    <option value="2">已签约</option>
                    <option value="3">已逾期</option>
                    <option value="4">暂缓推进</option>
                </select>
            </div>
        </div>

        <div style="display: block;margin-top:20px;">
            <div class="layui-btn layui-btn-sm js_search" data-type="reload">搜索</div>
            <div class="layui-btn layui-btn-sm js_relation" data-val="1">一键关联</div>
            <div class="layui-btn layui-btn-sm js_relation" data-val="2">一键解绑</div>
        </div>
    </form>
    <!--<div class="form-horizontal">-->
    <!--<div class="form-group" style="margin: 15px 0;">-->
    <!--<div class="input-group">-->
    <!--<input class="form-control" name="keyword" id="keyword" type="text" placeholder="输入项目名称进行搜索">-->
    <!--<select class="form-control">-->
    <!--<option>全部</option>-->
    <!--</select>-->
    <!--<div class="input-group-btn">-->
    <!--<a class="btn btn-primary js_search" href="javascript:;" ><i class="fa fa-search"></i> 搜索</a>-->
    <!--</div>-->
    <!--</div>-->
    <!--</div>-->
    <!--</div>-->
    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script type="text/html" id="barDemo1">


        {{# if (d.hasbeen=== 0) { }}
        <a class="layui-btn layui-btn-xs" lay-event="edit">关联</a>
        {{# } else { }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="unbundling">解绑</a>
        {{# } }}
    </script>
    <div class="assistant_button" style="display: none">
        <button type="button" class="layui-btn layui-btn-primary js_quit" close="true">取消</button>
        <button type="button" class="layui-btn js_add" _event="community_add" data-id="0" data-name="">保存</button>
    </div>
</div>

<script>
    var account_id = {$id};
    layui.form.render("select");
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery, layer = layui.layer;
        var table = layui.table //表格
        var form = layui.form;
        var associated = 0;
        form.on('select(associated)', function (data) {
            associated = data.value;
        });

        var library = 0;
        form.on('select(library)', function (data) {
            library = data.value;
        });

        var sign = 0;
        form.on('select(sign)', function (data) {
            sign = data.value;
        })

        var url = "{:URL('project/Communal/projectlists')}";
        //列表// {type: 'checkbox', fixed: 'left'}
        var where = {type: 'list', account_id: account_id};
        var title = "权限列表";
        //搜索操作
        $('.js_search').click(function () {
            var data=$("form[name='searchForm']").serializeArray();
            var dataVal = {};
            $.each(data, function(i, item){
                dataVal[item.name] = item.value;
            });
            var where = dataVal;
            search(table,url,where,'test')
        });

        //关联所有项目
        $(".js_relation").click(function () {
            var type = $(this).attr('data-val');
            $.ajax({
                type: "post",
                url: "{:URL('project/AccountPro/accountAll')}",
                data: {account_id: account_id, type: type, library: library,sign:sign},
                dataType: "json",
                success: function (data) {
                    if (data.code != 0) {
                        layer.alert(data.msg);
                    } else {
                        table.reload('test');
                    }
                }
            });
        });

        var cols = [[
            {field: 'id', title: 'ID', sort: true, width: 80, align: 'center'}
            , {field: 'title', title: '项目名称', width: 420, align: 'center'}
            , {field: 'onstream_time', title: '开工时间', width: 180, align: 'center', sort: true}
            , {fixed: 'right', title: '操作', align: 'center', width: 100, toolbar: '#barDemo1'}
        ]];
        showlist(table, url, where, title, cols, 0, 10, '#test', '');

        table.on('tool(test)', function (obj) {
            var id = obj.data.id;
            switch (obj.event) {
                case 'edit':
                    $.ajax({
                        type: "post",
                        url: "{:URL('project/AccountPro/accountpro')}",
                        data: {account_id: account_id, project_id: id},
                        dataType: "json",
                        success: function (data) {
                            if (data.code != 0) {
                                layer.alert(data.msg);
                            } else {
                                table.reload('test');
                            }
                        }
                    });
                    break;
                case 'unbundling':
                    $.ajax({
                        type: "post",
                        url: "{:URL('project/AccountPro/unbundling')}",
                        data: {account_id: account_id, project_id: id},
                        dataType: "json",
                        success: function (data) {
                            if (data.code != 0) {
                                layer.alert(data.msg);
                            } else {
                                table.reload('test');
                            }
                        }
                    });
                    break;
            }
        });


    });
</script>